class <%= @devise_model.pluralize %>::OmniauthCallbacksController < ApplicationController

  def callback
    provider = params[:provider]
    if not current_<%= @devise_scope %>.blank?
      current_<%= @devise_scope %>.bind_service(env["omniauth.auth"])
      sign_in_and_redirect(current_<%= @devise_scope %>, :notice => "Successfully binded to #{provider}.")
    else
      @<%= @devise_scope %> = <%= @devise_model %>.find_or_create_by_omniauth(env["omniauth.auth"])
      flash[:notice] = "Sign in with #{provider.to_s.titleize} successfully."
      sign_in_and_redirect @<%= @devise_scope %>, :event => :authentication, :notice => "Login successfully."
    end
  end

  def failure
    flash[:error] = params[:message]
    redirect_to root_path
  end

end
